package com.demo.simulation;

public class MyApplicationFilterChain implements MyFilterChain{

    MyFilterConfig[] myFilterConfigs = new MyFilterConfig[0];
    MyServlet servlet=null;
    private  int pos=0;
    private  int n=0;

    @Override
    public void doFilter(Object request, Object response) {
        internalDoFilter(request, response);
    }

    private void internalDoFilter(Object request,Object response){
        if (pos < n) {
            MyFilter filter = myFilterConfigs[pos++].getMyFilter();
            filter.doFilter(request,response,this);
            return;
        }
        servlet.service(request,response);
    }

    public void setMyFilterConfigs(MyFilterConfig[] myFilterConfigs) {
        this.myFilterConfigs = myFilterConfigs;
        this.n = myFilterConfigs.length;
    }

    public void setServlet(MyServlet servlet) {
        this.servlet = servlet;
    }
}
